<template>
  <div class="infoWindow">
    <div class="header-content">
      <div>围栏信息</div>
      <el-icon class="header-close" @click="handleClose"><ep-Close /></el-icon>
    </div>
    <div class="main-content">
      <el-row>
        <el-col :span="24" class="!flex">
          <div class="label">围栏类型：</div>
          <div class="flex-1">{{ railTypeOptions.find(item => item.value === railInfo.railType)?.label }}</div>
        </el-col>
        <el-col :span="24" class="!flex">
          <div class="label">围栏状态：</div>
          <div class="flex-1">{{ railStatusOptions.find(item => item.value === railInfo.railStatus)?.label }}</div>
        </el-col>
        <el-col :span="24" class="!flex">
          <div class="label">围栏地址：</div>
          <div class="flex-1">{{ railInfo.address }}</div>
        </el-col>
        <el-col v-if="railInfo.radius" :span="24" class="!flex">
          <div class="label">围栏半径[米]：</div>
          <div class="flex-1">{{ railInfo.radius }}</div>
        </el-col>
        <el-col :span="24" class="!flex">
          <div class="label">更新人：</div>
          <div class="flex-1">{{ railInfo.updateBy }}</div>
        </el-col>
        <el-col :span="24" class="!flex">
          <div class="label">更新时间：</div>
          <div class="flex-1">{{ railInfo.updateTime }}</div>
        </el-col>
      </el-row>

      <div v-if="allowEdit && railInfo.railType === 0" class="bottom-btn">
        <el-button type="primary" round @click="handleEditOverlay">编辑</el-button>
      </div>
    </div>

    <div class="arrows"></div>
  </div>
</template>

<script lang="ts" setup>
import { railTypeOptions, railStatusOptions } from '../options.ts'
import type { RailRowData } from '@/api/mixing-station/mixingStation'

const emit = defineEmits(['editOverlay', 'close'])

defineProps<{
  railInfo: RailRowData
  allowEdit: boolean
}>()

const handleClose = () => {
  emit('close')
}

const handleEditOverlay = () => {
  emit('editOverlay')
}
</script>
<style lang="scss" scoped>
.infoWindow {
  position: relative;
  width: 290px;
  border-radius: 6px;
  padding: 10px;
  box-sizing: border-box;
  box-shadow: 0 3px 12px 0 rgba(32, 40, 74, 0.3);
  background: var(--el-bg-color-overlay);
  font-size: 12px;
  .header-content {
    display: flex;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--el-border-color);
    box-sizing: border-box;
  }
  .header-close {
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 10px;
  }

  .main-content {
    padding-top: 10px;
    line-height: 16px;
    .label {
      font-weight: 600;
    }
  }
}
:deep(.el-col-24) {
  margin-bottom: 5px;
}

.bottom-btn {
  margin-top: 15px;
  display: flex;
  justify-content: center;
  .el-button {
    width: 155px;
  }
}

.arrows {
  width: 0;
  height: 0;
  border: 5px solid transparent;
  border-left-width: 8px;
  border-right-width: 8px;
  border-top-width: 10px;
  border-top-color: var(--el-bg-color-overlay);
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
}
</style>
